home *** CD-ROM | disk | FTP | other *** search
- Path: news.microsoft.com!news
- From: warlok@siu.edu (Jon Fincher)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: Q: Time to call a function?
- Date: 8 Jan 1996 15:00:48 GMT
- Organization: Microsoft Corp.
- Message-ID: <4crbj0$9v6@news.microsoft.com>
- References: <4cnjsf$kq0@mark.ucdavis.edu> <30F0E881.5F3D@vcx.net>
- NNTP-Posting-Host: 157.54.53.180
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In article <30F0E881.5F3D@vcx.net>, barnold@vcx.net says...
- >
- >> About how much time does calling a function, allocating memory, and
- >> executing simple statements like "i = 3" take?
- >
- >The Intel programmers reference manual lists the number of clocks for
- >each instruction. This varies from about 2 to 250. The above
- >assignment statement probably uses a memory MOV which may take 20 clocks
- >depending on the processor. A 'CALL' to a subroutine can take over 200.
- >Memory allocation might require many CALL's and other instructions
- >amounting to perhaps 10,000 to 100,000 clocks.
- >
- >To get back to 'time' (for the ballpark calculation) note that a
- >processor running at 66 MHZ has a clock time of 15 nanoseconds.
- >( 1 / 66,000,000 ). That memory allocation which required 100,000
- >clocks will take 1.5 milliseconds. That assignment will take
- >20 * 15ns = 300ns or 0.3 microsecs.
- >
- >It can be very tedious to try to calculate the exact value by looking
- >at the assembly source code; that's what benchmarks are for.
- >Note also that in real computers, most of the time is spent doing data
- >input / output to storage devices and sending data to the screen.
-
- Bruce:
-
- You also might want to mention pipelining, which speeds up a lot of
- processors.
-
- Pipelining is the ability of a microprocessor to work on more than one
- instruction at a time. For example, there are a few basic steps to executing
- an assembly instruction :
-
- 1) Fetch the instruction. This entails reading the assembly code from memory
- and placing it in a processor register.
-
- 2) Decode the instruction. This is a proces by which the processor figures
- out what the instruction means.
-
- 3) Fetch the data. Any data the instruction needs is in memory following the
- actual instruction. This is where the data is retrieved.
-
- 4) Execute the instruction. This is an obvious step.
-
- A microprocessor can speed operations up by pipelining instructions, i.e.
- having a different instruction in each step. For example, in our model above,
- we could be executing Inst. A, fetching the dat for Inst. B, Decoding Inst. C,
- and fetching Inst. D, so the processor is working on four instructions at
- once. Each instruction may take multiple clock cycles, ut now the clock
- cycles required for one instruction overlap the clock cycles required for
- neighbor instructions, reducing the overall clock cycle requirements and
- speeding the program up.
-
- Most compilers are designed to take advantage of pipelining by keeping low
- clock cycle instructions together and not using (if possible) large clock
- cycle instructions. Large clock cycle instructions back pipelines up.
-
- Any other comments? Did I miss anything?
-
- Jon
-
-